package com.woniuxy.table.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.table.client.TableTypeQueryClient;
import com.woniuxy.table.client.result.DinnerTableTypeClientDto;
import com.woniuxy.table.infra.model.DinnerTableType;
import com.woniuxy.table.service.DinnerTableTypeService;
import exception.MallException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.CommonResultCodeEnum;
import result.Result;

import java.util.List;

@RestController
public class TableTypeQueryApiImpl implements TableTypeQueryClient {
    @Autowired
    private DinnerTableTypeService dinnerTableTypeService;
    @Log("查询餐桌类型")
    @Override
    public Result<DinnerTableTypeClientDto> getTableType(Integer storeId, Integer tableTypeId) {
        DinnerTableType dinnerTableType = dinnerTableTypeService.getTableType(storeId,tableTypeId);
        DinnerTableTypeClientDto dinnerTableTypeClientDto = BeanUtil.toBean(dinnerTableType, DinnerTableTypeClientDto.class);
        return Result.success(dinnerTableTypeClientDto);
    }
    @Log("查询餐桌类型")
    @Override
    public Result<List<DinnerTableTypeClientDto>> getAllTableType(Integer storeId) {
        List<DinnerTableType> list = dinnerTableTypeService.getAllTableType(storeId);
        if (list==null){
            throw new MallException("餐桌类型不存在", CommonResultCodeEnum.INVALID_PARAM);
        }
            List<DinnerTableTypeClientDto> list1 = BeanUtil.copyToList(list, DinnerTableTypeClientDto.class);

        return Result.success(list1);
    }
}
